home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / ASSEMBLE / 2322C.ZIP / A68 / LABGEN.ASM < prev    next >
Assembly Source File  |  1990-08-16  |  2KB  |  55 lines

  1. .title "Label Generation Example"
  2. ; Some useful macros to help get you started.
  3. ;
  4. ; Please note that all of the examples use 6800 instructions and thus
  5. ; will generate error messages when assembled on other assemblers. Just
  6. ; ignore (or substitute the equivalent opcode for your processor) those
  7. ; messages--the macro ideas depicted are still valid.
  8. ;
  9.  
  10. ; Unique generated labels.
  11. ;
  12. ; Some macros will require "local" labels unique to a given expansion.
  13. ; The following macros are one way of creating them.
  14. ;
  15.  
  16. ; nlabel creates a new unique identifier (of the form l1nnnn, where n varies)
  17. ; each invocation.
  18. ;
  19. ; nlabel returns the current value of glabel, and then redefines glabel to
  20. ; the value one greater than glabel.
  21. ;
  22.          define( glabel,10000)
  23.          define( nlabel,``l'glabel`'define(`glabel',iner(glabel))')
  24. ;
  25. ; Now we have a unique label generator, but each time we call it the label
  26. ; will be different, and thus of little use for branches and jumps.
  27. ;
  28. ; We must assign this unique label string to an identifier for multiple
  29. ; uses.
  30. ;
  31.          define(local1,nlabel)
  32. local1:  nop
  33.          jmp local1
  34.          jsr local1
  35.          undefine(`local1')
  36. local1:  nop
  37. ;
  38. ; Above we define local1 to be the string generated by nlabel, use that
  39. ; string in several places, and then undefine it. Note that local1 after
  40. ; the undefine is "local1" and not a generated string. If defined locals
  41. ; are not undefined when we are done with them, we would quickly run out
  42. ; of memory space.
  43.  
  44. ;
  45.  
  46.         define(loop, ` define(local1,nlabel)
  47. local1:  nop
  48.          jmp local1
  49.          undefine(`local1')')
  50.  
  51.    loop
  52.    loop
  53.    loop
  54.  
  55.